/**
 * jQuery.simpleScroll - Simple way to scroll through content/images.
 * Copyright (c) 2010 Cory Dorning - cory.dorning|at|gmail|dot|com | http://www.corydorning.com
 * Dual licensed under MIT and GPL.
 * Date: 05/16/2010
 * @author Cory Dorning
 * @version 1.03
 *
 * http://www.corydorning.com/projects/simpleScroll
 */
(function($) {
	$.fn.simpleScroll = function(params) {
		var defaults = {  // set plug-in defaults
					event: 'click',
					prev: '.prev',
					next: '.next',
					speed: 1000,
					stop: false  // not being used yet
				};
		var options = $.extend(defaults, params);
		var $container = $(this);
		var $controls = [ $(options.prev), $(options.next) ];
		var children = $container.children();
		var posLeft = $container.position().left;
		var counter = 0;

		$container.width( sizeContainer(children) );

		$controls[0].bind(options.event, function() {
			posLeft += $(children[counter]).outerWidth();
			counter--;
			animateSlider(posLeft);
			arrowDisplay();
		});

		$controls[1].bind(options.event, function() {
			posLeft -= $(children[counter]).outerWidth();
			counter++;
			animateSlider(posLeft);
			arrowDisplay();
		});

		function sizeContainer(child) {
			var width = 0;  // init width

			$.each(child,function() {
				width += $(this).outerWidth();  // add to width
			});

			return width;
		}

		function animateSlider(posLeft) {
			$container.animate({
				left: posLeft
			},options.speed);
		}

		function arrowDisplay() {
			$.each($controls, function(i) {
				if (counter == 0 && i == 0) {
					$(this).addClass('invis');
				} else if (counter == children.length-1 && i == 1) {
					$(this).addClass('invis');
				} else {
					$(this).removeClass('invis');
				}
			});
		}
	};
})(jQuery);